function getBaseUrl()
{
	var l = window.location;
	var base_url = l.protocol + "//" + l.host + "/" + l.pathname.split('/')[1];
	return base_url;
}


$(document).ready(function() {
	$('#content_wrapper div').hide();
	$('#content_wrapper div:first').show();
	$('#settings ul li:first').addClass('current');

	$('#settings li a').click(function() {
		$('#settings li a').removeClass('current');
		$(this).parent().addClass('current');
		var currentTab = $(this).attr('href');
		$('#content_wrapper div').hide();
		$(currentTab + "Panes").show();
		return false;
	});
	$(".tabitem").click(function(){
		$('.pager').show();
	});
	$("#category").click(function(){
	    $("#expensecategory-grid").show();
		if( $('#expensecategory-grid').text() !== '')
			return false;
		 
		 var paddingDataShowPanel = "#expensecategory-grid";
		 var ajaxUrl = getBaseUrl()+'/index.php/settings/loadexpensecategory';
		 var values = "loadDefault=1";
		 $("#paggingAjaxUrl").val(ajaxUrl);
		 $("#paddingDataShowPanel").val(paddingDataShowPanel);
		  paggingAjaxExecute(values,ajaxUrl,paddingDataShowPanel);
	});
	$("#userManagement").click(function() {

		$('.tablesorter-wrapper').show();

		$('.tablesorter-header-inner').show();
		$('#tree').show();
	});
	
});

$(function(){
		$("#tree").dynatree({
			checkbox: true,
			onSelect: function(flag, node) {

				var selectedNodes = node.tree.getSelectedNodes();
				var selectedKeys = $.map(selectedNodes, function(node){
					return node.data.key;
				});
				$('#roles').val(selectedKeys.join(", "));
			},
			// Override class name for checkbox icon, so rasio buttons are displayed:
			//classNames: {checkbox: "dynatree-radio"},
			// Select mode 3: multi-hier
			selectMode: 3,
			children: [
				{title: "Expenses Form", key: "M002",
					children: [
						{title: "View Form", key: "M002-000"},					
						{title: "Create new expense", key: "M002-001"},
						{title: "Edit expense", key: "M002-002"},
						{title: "Edit Multiple expenses", key: "M002-003"},
						{title: "Delete expense", key: "M002-004"},
						{title: "Merge expenses", key: "M002-005"},
						{title: "Export to Exel", key: "M002-006"},
						{title: "Add to report", key: "M002-007"},
						{title: "Save to analysis", key: "M002-008"},
						{title: "Filter", key: "M002-009"},
						{title: "Approval Workflow", key: "M002-010"},
						{title: "Admin management", key: "M002-011"},
					]				
				},
				{title: "Receipts Form",key: "M0003",
					children: [
						{title: "View Form", key: "M003-000"},
						{title: "Add new receipt", key: "M003-001"},
						{title: "Delete receipts", key: "M003-002"},
						{title: "Merge receipts", key: "M003-003"},
						{title: "Filter receipts", key: "M003-004"},
					]
				},
				{title: "Reports", key: "M004",
					children: [
						{title: "Expense reports",key: "M004-a",
							children: [
								{title: "View Form", key: "M004-000"},
								{title: "Create new report", key: "M004-001"},
								{title: "View report, and print it", key: "M004-002"},
								{title: "Filter report", key: "M004-003"},
								{title: "Admin management", key: "M004-004"},
								]
							},	
						{title: "Standard reports",key: "M004-b",
							children: [
								{title: "View Form", key: "M004-005"},
								{title: "Create new report", key: "M004-006"},
								{title: "View report, and print it", key: "M004-007"},
								{title: "Filter report", key: "M004-008"},
								{title: "Admin management", key: "M004-00"},
								]
							},			
						]
					},
					{title: "Analysis Form",key: "M005",
						children: [
							{title: "View Form", key: "M005-000"},
							{title: "View analysis in detail", key: "M005-001"},
						]
				},
				{title: "Settings Form", key: "M007",
					children: [
					 
						{title: "Customer",key: "M007-001",
							children: [
								{title: "View Form", key: "M007-001-000"},
								{title: "Add New", key: "M007-001-001"},
								{title: "Edit", key: "M007-001-002"},
								{title: "Delete", key: "M007-001-003"},
								{title: "Comment", key: "M007-001-004"},
								]
							},	
						{title: "Category of Expense",key: "M007-002",
							children: [
								{title: "View Form", key: "M007-002-000"},
								{title: "Add New", key: "M007-002-001"},
								{title: "Edit", key: "M007-002-002"},
								{title: "Delete", key: "M007-002-003"},
								]
							},
						{title: "Currency",key: "M007-003",
							children: [
								{title: "View Form", key: "M007-003-000"},
								{title: "Add New", key: "M007-003-001"},
								{title: "Edit", key: "M007-003-002"},
								{title: "Delete", key: "M007-003-003"},
								]
							},	
						{title: "Unit of Measure",key: "M007-004",
							children: [
								{title: "View Form", key: "M007-004-000"},
								{title: "Add New", key: "M007-004-001"},
								{title: "Edit", key: "M007-004-002"},
								{title: "Delete", key: "M007-004-003"},
								]
							},
						{title: "Department",key: "M007-005",
							children: [
								{title: "View Form", key: "M007-005-000"},
								{title: "Add New", key: "M007-005-001"},
								{title: "Edit", key: "M007-005-002"},
								{title: "Delete", key: "M007-005-003"},
								]
							},
						{title: "Company",key: "M007-006",
							children: [
								{title: "View Form", key: "M007-006-000"},
								{title: "Add New", key: "M007-006-001"},
								{title: "Edit", key: "M007-006-002"},
								{title: "Delete", key: "M007-006-003"},
								]
							},																												
						]
					},					
			]
		});
		
		
		
	   	
		/**
		 *Ajax for setting  the create user form 
		 */
		// $("#setting-create-user-form").submit(function(event) {
//   
			    // /* Stop form from submitting normally */
			    // event.preventDefault();
			    // /* Get some values from elements on the page: */
		       // var values = $(this).serialize();
//                
		        // $.ajax({
		        // url: getBaseUrl()+"/index.php/user/create",
		        // type: "post",
		        // data: values,
		        // success: function(data){
		           // alert("Sucessfuly");
		        // },
		        // error:function(){
// 		            
		            // alert('There is error while submit');
		            // //$("#result").html('There is error while submit');
		        // }
		    // });
		  // });

		$('.semwal_dtpicker').datepicker();	
	});
